#!ipxe

# Arch Linux Operating System
# http://www.archlinux.org

set os_arch ${arch}
iseq ${os_arch} x86_64 && set os_arch x86_64 ||
iseq ${os_arch} i386 && set os_arch i686 ||
isset ${dhcp-server} || goto static_ip
set ipparam BOOTIF=${netX/mac} ip=dhcp
set real_archlinux_mirror ${archlinux_mirror}
goto goto_menu

:static_ip
# Arch Linux cannot use DNS if booted with a static IP
# See https://bugs.archlinux.org/task/63174
# Remove this hack when the above bug is properly resolved
nslookup real_archlinux_mirror ${archlinux_mirror}
set ipparam BOOTIF=${netX/mac} ip=${ip}::${gateway}:${netmask}

:goto_menu
goto ${menu} ||

:archlinux
set os {{ releases.archlinux.name }}
clear arch_version
menu ${os} - ${arch}
item --gap Latest Releases
{% for item in releases.archlinux.versions %}
item {{ item.code_name }} ${space} ${os} {{ item.name }}
{% endfor %}
choose arch_version || goto archlinux_exit
iseq ${os_arch} amd64 && goto boot ||
iseq ${os_arch} i686 && goto boot32 ||

:boot
imgfree
set dir ${archlinux_base_dir}/iso/${arch_version}/arch/boot
set params archiso_http_srv=http://${real_archlinux_mirror}/${archlinux_base_dir}/iso/${arch_version}/ archisobasedir=arch verify=y ${ipparam} net.ifnames=0 {{ kernel_params }}
kernel http://${archlinux_mirror}/${dir}/${os_arch}/vmlinuz-linux ${params}
initrd http://${archlinux_mirror}/${dir}/${os_arch}/initramfs-linux.img
echo
echo MD5sums:
md5sum vmlinuz-linux initramfs-linux.img
boot
goto archlinux_exit

:boot32
{% for key, value in endpoints.items() | sort %}
{% if key == "archlinux-32" %}
set arch32_url ${live_endpoint}{{ value.path }}
{% endif %}
{% endfor %}
imgfree
set params archiso_http_srv=${arch32_url} archisobasedir=arch checksum=y ${ipparam} net.ifnames=0 {{ kernel_params }}
kernel ${arch32_url}vmlinuz-linux ${ipparam} ${params}
initrd ${arch32_url}initramfs-linux.img
echo
echo MD5sums:
md5sum vmlinuz-linux initramfs-linux.img
boot
goto archlinux_exit

:archlinux_exit
clear menu
exit 0
